package thread.thread4;

public class MoneySaver extends Thread {
	private Account ac;

	public MoneySaver(String name, Account ac) {
		super(name);
		this.ac = ac;
	}

	@Override
	public void run() {
		while (true) {

			try {
				sleep(1500);

				synchronized (ac) {
					ac.saveMoney(15000);
					System.out.println(getName() + "存钱了，当前账户余额为" + ac.getBalance() + "元");
					ac.notifyAll();

				}

			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}
}
